package com.csun.cmny.provider.controller.admin;

import com.csun.cmny.core.support.BaseController;
import com.csun.cmny.provider.model.domain.DmcRfidLabelRole;
import com.csun.cmny.provider.model.dto.rfid.RfidLabelRolePageQuery;
import com.csun.cmny.provider.model.vo.rfid.RfidLabelRoleVo;
import com.csun.cmny.provider.resolver.CmnyMessageSource;
import com.csun.cmny.provider.service.DmcRfidLabelRoleService;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import com.github.pagehelper.PageInfo;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-12-07 09:23
 * @Description:
 */
@RestController
@RequestMapping(value = "/rfidLabelRole", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class DmcRfidLabelRoleController extends BaseController {

    @Resource
    private CmnyMessageSource cmnyMessageSource;
    @Resource
    private DmcRfidLabelRoleService dmcRfidLabelRoleService;

    /**
     * 查询列表
     *
     * @return
     */
    @PostMapping(value = "/queryListWithPage")
    public Wrapper queryListWithPage(@RequestBody RfidLabelRolePageQuery rfidLabelRolePageQuery) {

        rfidLabelRolePageQuery.setGroupId(getLoginAuthDto().getGroupId());

        List<RfidLabelRoleVo> rfidLabelRoleVoList = dmcRfidLabelRoleService
                .queryListWithPage(rfidLabelRolePageQuery);

      //  return WrapMapper.ok(new PageInfo<>(rfidLabelRoleVoList));
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),new PageInfo<>(rfidLabelRoleVoList));
    }

    /**
     * 查询全部
     */
    @PostMapping(value = "/queryAll")
    public Wrapper queryAll() {

        List<RfidLabelRoleVo> rfidLabelRoleVoList = dmcRfidLabelRoleService
                .queryAll(getLoginAuthDto().getGroupId());

       // return WrapMapper.ok(rfidLabelRoleVoList);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),rfidLabelRoleVoList);
    }

    /**
     * 添加
     */
    @PostMapping(value = "/add")
    public Wrapper add(@RequestBody DmcRfidLabelRole dmcRfidLabelRole) {

        Integer result = dmcRfidLabelRoleService.add(dmcRfidLabelRole, getLoginAuthDto());
        if (result < 1) {
            return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
                    .getMessage("operation.failed", null));
        }

       // return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }

    /**
     * 修改
     */
    @PostMapping(value = "/edit")
    public Wrapper edit(@RequestBody DmcRfidLabelRole dmcRfidLabelRole) {

        Integer result = dmcRfidLabelRoleService.edit(dmcRfidLabelRole, getLoginAuthDto());
        if (result < 1) {
            return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
                    .getMessage("operation.failed", null));
        }

       // return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }

    /**
     * 删除
     */
    @PostMapping(value = "/deleteById/{id}")
    public Wrapper deleteById(@PathVariable Long id) {

        Integer result = dmcRfidLabelRoleService.deleteById(id);
        if (result < 1) {
            return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
                    .getMessage("operation.failed", null));
        }

      //  return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }
}
